﻿using System.Collections.Generic;
using System.Linq;
using System.Threading;
using MediaAssistant.DAL;
using MediaAssistant.DAL.Constants;

namespace MediaAssistant.Management
{
    public abstract class MusicTagSynchronizer:BackgroundScanner
    {
        protected override void TryToScan()
        {
            var musicToSync = GetMusicToSync();
            if (musicToSync == null || !musicToSync.Any()) return;
            
            foreach (var music in musicToSync)
            {
                if (Job.Store.StopRequested)
                {
                    return;
                }
                Thread.Sleep(1000);
                PauseIfRequested();
                if(music.Status==MusicStatus.Playing)
                    continue;
                SetStatusMessage(string.Format("{0} Syncing {1}",Name, music.FullPath));
                SyncTag(music);
            }
            SetStatusMessage("Ready");
        }

        protected abstract void SyncTag(Music music);

        protected abstract IEnumerable<Music> GetMusicToSync();
    }
}
